package com.jy.rhin.support.polymorphism.convertor;

import cn.org.chiss.rhin._2015.document.management.DocumentStoredQueryResponse;
import com.jy.rhin.sdk.dto.document.DocumentEntryDto;
import com.jy.rhin.sdk.dto.document.DocumentResultDto;
import com.jy.rhin.sdk.dto.document.query.FindDocumentsDto;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author dhl
 * @date 2022/6/21
 * @Description
 */
@Service("findDocuments")
public class DocumentQueryHandler4FindDocuments extends AbstractDocumentQueryHandler<FindDocumentsDto, DocumentEntryDto> {

    @Override
    FindDocumentsDto convertReq(Map<String, List<String>> dtoValueMap) {
        FindDocumentsDto dto = new FindDocumentsDto();
        dto.setPatientId(QueryValueUtils.getStringValue("$DocumentEntryPatientId", dtoValueMap));
        dto.setStatusCodeList(QueryValueUtils.getListValue("$DocumentEntryStatus", dtoValueMap));
        dto.setClassCodeList(QueryValueUtils.getListValue("$DocumentEntryClassCode", dtoValueMap));
        dto.setTypeCodeList(QueryValueUtils.getListValue("$DocumentEntryTypeCode", dtoValueMap));
        dto.setPracticeSettingCodeList(QueryValueUtils.getListValue("$DocumentEntryPracticeSettingCode", dtoValueMap));
        dto.setCreationTimeStart(QueryValueUtils.getDateValue("$DocumentEntryCreationTimeFrom", dtoValueMap));
        dto.setCreationTimeEnd(QueryValueUtils.getDateValue("$DocumentEntryCreationTimeTo", dtoValueMap));
        dto.setServiceStartTimeStart(QueryValueUtils.getDateValue("$DocumentEntryServiceStartTimeFrom", dtoValueMap));
        dto.setServiceStartTimeEnd(QueryValueUtils.getDateValue("$DocumentEntryServiceStartTimeTo", dtoValueMap));
        dto.setServiceStopTimeStart(QueryValueUtils.getDateValue("$DocumentEntryServiceStopTimeFrom", dtoValueMap));
        dto.setServiceStopTimeEnd(QueryValueUtils.getDateValue("$DocumentEntryServiceStopTimeTo", dtoValueMap));
        dto.setHealthcareFacilityTypeCodeList(QueryValueUtils.getListValue("$DocumentEntryHealthcareFacilityTypeCode", dtoValueMap));
        dto.setEventCodeList(QueryValueUtils.getListValue("$DocumentEntryEventCodeList", dtoValueMap));
        dto.setConfidentialityCodeList(QueryValueUtils.getListValue("$DocumentEntryConfidentialityCode", dtoValueMap));
        dto.setFormatCodeList(QueryValueUtils.getListValue("$DocumentEntryFormatCode", dtoValueMap));
        return dto;
    }

    @Override
    DocumentResultDto<DocumentEntryDto> query(FindDocumentsDto dto) {
        return documentSubmissionQueryHandler.findDocuments(dto);
    }

    @Override
    DocumentStoredQueryResponse convertResp(List<DocumentEntryDto> resultList, List<String> jsonTextList) {
        return entryConvert(resultList, jsonTextList);
    }
}
